home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / Stars4.s < prev    next >
Encoding:
Text File  |  1997-07-08  |  7.3 KB  |  265 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      3D StarField 4
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;This is a demo of a triple buffered starfield.  I didn't orginally write
  7. ;this starfield code, but it was very old so it needed a fair bit of
  8. ;cleaning up to work with the library.  It now runs in 4 colours for a
  9. ;little more depth too...
  10.  
  11.     INCDIR    "INCLUDES:"
  12.     INCLUDE    "games/games_lib.i"
  13.     INCLUDE    "games/games.i
  14.  
  15. NSTARS    =    800                     ;Number of stars
  16.  
  17. XSPEED    =    -4
  18. YSPEED    =    6
  19. ZSPEED    =    2
  20.  
  21. SCRWIDTH =    320
  22. SCRHEIGHT =    256
  23.  
  24.     SECTION    "Stars",CODE
  25.  
  26. ;==========================================================================;
  27. ;                             INITIALISE DEMO
  28. ;==========================================================================;
  29.  
  30.     STARTGMS
  31.  
  32. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  33.     move.l    GMSBase(pc),a6
  34.     lea    ScreenTags(pc),a0
  35.     CALL    ShowScreen
  36.     tst.l    d0
  37.     beq.s    .Error_Screen
  38.  
  39.     CALL    InitJoyPorts
  40.  
  41.     bsr.s    Main
  42.  
  43. .ReturnToDOS
  44.     move.l    GMSBase(pc),a6
  45.     move.l    Screen(pc),a0
  46.     CALL    DeleteScreen
  47. .Error_Screen
  48.     MOVEM.L    (SP)+,A0-A6/D1-D7
  49.     moveq    #ERR_OK,d0
  50.     rts
  51.  
  52. ;==========================================================================;
  53. ;                                 INITIALISE
  54. ;==========================================================================;
  55.  
  56.     ;Randomize star coordinates
  57.  
  58. Main:    lea    StarCoords,a0            ;a0 = Ptr to star co-ordinates.
  59.     move.w    #NSTARS-1,d7
  60. .loop1    move.w    #8192,d1
  61.     CALL    SlowRandom
  62.     move.w    d0,(a0)+
  63.     CALL    SlowRandom
  64.     move.w    d0,(a0)+
  65.     CALL    SlowRandom
  66.     move.w    d0,(a0)+
  67.     dbra    d7,.loop1
  68.  
  69.     ;Construct perspective table
  70.  
  71.     lea    PersTable,a0             ;a0 = ptr to perspective table.
  72.     moveq    #0,d1                    ;d1 = Starting at 0.
  73. .loop2    move.l    #$95FFFF,d2              ;d2 = $95FFFF
  74.     move.l    d1,d3                    ;d3 = d1
  75.     add.w    #300,d3                  ;d3 = ++300
  76.     divu    d3,d2                    ;d2 = ($95ffff)/d3
  77.     move.w    d2,(a0)+                 ;a0 = d2+
  78.     addq.w    #1,d1                    ;d1 = ++1
  79.     cmp.w    #8192,d1                 ;d1 = Equal to 8192?
  80.     bne.s    .loop2
  81.  
  82.     ;Construct plot tables for fast drawing.
  83.  
  84.     lea    PlotXTable,a0            ;a0 = X table - byte positions.
  85.     lea    PlotBTable,a1            ;a1 = Bit table (X related).
  86.     lea    PlotYTable,a2            ;a2 = Y table - line position.
  87.     moveq    #0,d0                    ;d0 = 00
  88. .loop3    move.w    d0,d1                    ;d1 = d0
  89.     lsr.w    #3,d1                    ;d1 = (d0)<<3
  90.     move.w    d1,(a0)+                 ;a0 = d1+
  91.  
  92.     move.w    d0,d1                    ;d1 = d0
  93.     eor.w    #$FFFF,d1                ;d1 = (d0) eor $ffff
  94.     and.w    #%00000111,d1            ;d1 = &%00000111
  95.     move.w    d1,(a1)+                 ;a1 = BitSet++
  96.  
  97.     cmp.w    #SCRHEIGHT,d0    ;Write out the Y values for the
  98.     bge.s    .plot2    ;table.
  99.     move.w    d0,d1    ;d1 = Line Number.
  100.     mulu    #80,d1    ;d1 = (LineNumber)*80
  101.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  102.  
  103. .plot2    addq.w    #1,d0
  104.     cmp.w    #SCRWIDTH,d0
  105.     bne.s    .loop3
  106.  
  107. ;==========================================================================;
  108. ;                                MAIN LOOP
  109. ;==========================================================================;
  110.  
  111. MainLoop:
  112.     move.l    GMSBase(pc),a6
  113.     move.l    Screen(pc),a0
  114.     CALL    WaitVBL
  115.     CALL    SwapBuffers
  116.  
  117. ;==========================================================================;
  118. ;                             STAR ANIMATION
  119. ;==========================================================================;
  120.  
  121.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  122.     add.w    #XSPEED,d0               ;d0 = (StarXPos)+XSPEED
  123.     add.w    #YSPEED,d1               ;d1 = (StarYPos)+YSPEED
  124.     add.w    #ZSPEED,d2               ;d2 = (StarZPos)+ZSPEED
  125.     and.w    #%0000011111111111,d0
  126.     and.w    #%0000011111111111,d1
  127.     and.w    #%0000011111111111,d2
  128.     movem.w    d0/d1/d2,StarXPos
  129.  
  130.     lea    Sinus(pc),a0             ;a0 = Sinus table.
  131.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  132.     add.w    (a0,d0.w),d3
  133.     add.w    (a0,d1.w),d4
  134.     add.w    (a0,d2.w),d5
  135.     movem.w    d3/d4/d5,StarXAdd
  136.  
  137. ;===========================================================================;
  138. ;                              SCREEN CLEAR
  139. ;===========================================================================;
  140.  
  141.     move.l    GMSBase(pc),a6
  142.     move.l    Screen(pc),a1    ;a1 = GameScreen
  143.     move.l    GS_Bitmap(a1),a0    ;a0 = Bitmap
  144.     move.l    GS_MemPtr3(a1),BMP_Data(a0)
  145.     CALL    ClearBitmap
  146.  
  147. ;==========================================================================;
  148. ;                               DRAW STARS
  149. ;==========================================================================;
  150.  
  151.     lea    StarCoords,a0            ;Draw starfield
  152.     lea    PersTable,a1
  153.     lea    PlotXTable,a2
  154.     lea    PlotBTable,a3
  155.     lea    PlotYTable,a4
  156.     move.l    Screen(pc),a6
  157.     move.l    GS_MemPtr2(a6),a6
  158.  
  159.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  160.     add.w    #4096,d3                 ;d3 = ++4096
  161.     add.w    #4096,d4                 ;d4 = ++4096
  162.  
  163.     move.w    #NSTARS-1,d7
  164.  
  165. .draw1    movem.w    (a0)+,d0/d1/d2           ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  166.     add.w    d3,d0                    ;Increase XPos.
  167.     and.w    #8191,d0                 ;d0 = And'd
  168.     sub.w    #4096,d0                 ;d0 = --4096
  169.  
  170.     add.w    d4,d1                    ;Y-movement
  171.     and.w    #8191,d1                 ;d1 = And'd
  172.     sub.w    #4096,d1                 ;d1 = --4096
  173.  
  174.     add.w    d5,d2                    ;Z-movement
  175.     and.w    #8191,d2
  176.     add.w    d2,d2                    ;d2 = *2 [word]
  177.     move.w    (a1,d2.w),d6             ;d6 = Read from Perspective table.
  178.  
  179.     muls    d6,d0                    ;X-projection
  180.     swap    d0
  181.     add.w    #176,d0
  182.  
  183.     cmp.w    #SCRWIDTH-1,d0
  184.     bhi.s    .nodraw
  185.     muls    d6,d1                    ;Y-projection
  186.     swap    d1
  187.     add.w    #136,d1
  188.     cmp.w    #SCRHEIGHT-1,d1
  189.     bhi.s    .nodraw
  190.  
  191.     add.w    d0,d0                    ;d0 = *2 [word]
  192.     add.w    d1,d1                    ;d1 = *2 [word]
  193.     move.w    (a4,d1.w),d6             ;d6 = Plot Y.
  194.     add.w    (a2,d0.w),d6             ;d6 = ++PlotX.
  195.     move.w    (a3,d0.w),d0             ;d0 = BitValue.
  196.  
  197.     cmp.w    #7000,d2                 ;Now draw the star according to
  198.     bgt.s    .draw2                   ;its position in the Z axis.
  199.     bset    d0,(a6,d6.w)
  200.     dbra    d7,.draw1
  201.     bra.s    .done
  202.  
  203. .draw2    cmp.w    #13000,d2
  204.     bgt.s    .draw3
  205.     bset    d0,SCRWIDTH/8(a6,d6.w)
  206.     dbra    d7,.draw1
  207.     bra.s    .done
  208.  
  209. .draw3    bset    d0,(a6,d6.w)
  210.     bset    d0,SCRWIDTH/8(a6,d6.w)
  211. .nodraw    dbra    d7,.draw1
  212.  
  213. .done    move.l    GMSBase(pc),a6
  214.     moveq    #JPORT1,d0    ;Read from port 1 (mouse).
  215.     moveq    #JT_ZBXY,d1
  216.     CALL    ReadJoyPort    ;Go get joystick status.
  217.     btst    #MB_LMB,d0
  218.     beq    MainLoop
  219.     rts
  220.  
  221. ;===========================================================================;
  222. ;                                  DATA
  223. ;===========================================================================;
  224.  
  225. ScreenTags:
  226.     dc.l    TAGS_GAMESCREEN
  227. Screen:    dc.l    0
  228.     dc.l    GSA_Palette,.palette
  229.     dc.l    GSA_ScrWidth,SCRWIDTH
  230.     dc.l    GSA_ScrHeight,SCRHEIGHT
  231.     dc.l    GSA_Planes,2
  232.     dc.l    GSA_Attrib,TPLBUFFER
  233.     dc.l    GSA_ScrType,ILBM
  234.     dc.l    TAGEND
  235.  
  236. .palette
  237.     dc.l    $000000,$D0D0D0,$606060,$202020
  238.  
  239. ;===========================================================================;
  240. ;                                STAR DATA
  241. ;===========================================================================;
  242.  
  243. StarXAdd dc.w    33                       ;Star stuff
  244. StarYAdd dc.w    12
  245. StarZAdd dc.w    -114
  246.  
  247. StarXPos dc.w    0                        ;Sinus positions
  248. StarYPos dc.w    310
  249. StarZPos dc.w    1280
  250.  
  251.     INCLUDE    "GMS:source/asm/demos/StarSinus.i"
  252.  
  253.     SECTION    Storage,BSS
  254.  
  255. StarCoords
  256.     ds.w    NSTARS*3                 ;Star coordinates
  257.  
  258. PersTable
  259.     ds.w    8192                     ;Perspective table
  260.  
  261. PlotXTable ds.w    SCRWIDTH                ;Plot tables
  262. PlotBTable ds.w    SCRWIDTH
  263. PlotYTable ds.w    SCRHEIGHT
  264.  
  265.